package cn.wizzer.app.web.modules.controllers.platform.user.chat.attendant;

import cn.wizzer.app.user.modules.models.enums.MsgStatusEnum;
import cn.wizzer.app.user.modules.models.enums.MsgTypeEnum;
import cn.wizzer.app.user.modules.models.vo.ChatUserMsgVO;
import cn.wizzer.app.user.modules.services.UserChatMsgService;
import cn.wizzer.app.user.modules.services.UserService;
import cn.wizzer.framework.base.Result;
import com.alibaba.dubbo.config.annotation.Reference;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.nutz.dao.Chain;
import org.nutz.dao.Cnd;
import org.nutz.dao.Sqls;
import org.nutz.dao.util.cri.Static;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Strings;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

@IocBean
@At("/platform/user/attendant")
public class AttendantRecordController {
    private static final Log log = Logs.get();

    @Inject
    @Reference
    private UserChatMsgService userChatMsgService;

    @Inject
    @Reference
    private UserService userService;

    @At("/")
    @Ok("beetl:/platform/user/chat/attendant/index.html")
    @RequiresPermissions("user.attendant")
    public void index() {
    }

    /**
     * 查询（分页）
     *
     * @return Object
     */
    @At
    @Ok("json:full")
    @RequiresPermissions("user.attendant")
    public Object data(@Param("sender") String sender,
                       @Param("receiver") String receiver,
                       @Param("searchDate") String[] searchDate,
                       @Param("type") MsgTypeEnum type,
                       @Param("status") MsgStatusEnum status,
                       @Param("pageNumber") int pageNumber,
                       @Param("pageSize") int pageSize) {
        return Result.success().addData(userChatMsgService.listPage(pageNumber, pageSize, sender, receiver, searchDate, type, status));
    }

    /**
     * 审核
     *
     * @return Object
     */
    @At("/record/delete")
    @Ok("json:full")
    @RequiresPermissions("user.attendant.record.delete")
    public Object delete(String id) {
        userChatMsgService.update(Chain.make("status", MsgStatusEnum.DELETED), Cnd.where("id", "=", id));
        return Result.success();
    }

}
